<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/jquery-3.5.1.min.js"></script>
</head>
<body>

<form action="#" method="post" id="favorites_form">
    商品id: <input type="text" name="commodityId" id="commodityName"/> <br>
    用户id: <input type="text" name="userId"/> <br>
    <input type="button" value="添加到收藏夹" id="btn_save">
</form>
<a href="http://localhost:8081/favorites/detail">查看收藏夹</a>
<script>
    $("#btn_save").click(function () {
        $.ajax(
            {
                url: "http://localhost:8081/favorites/save",
                type: "post",
                dataType: "json",
                data: $("#favorites_form").serialize(),
                success: function (data) {
                    if (data == 1) {
                        alert("收藏成功");
                    } else {
                        alert("收藏失败");
                    }
                }
            }
        )
    })
</script>
</body>
</html>